home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / c / memcmp < prev    next >
Text File  |  1996-11-09  |  2KB  |  75 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/c/RCS/memcmp,v $
  4.  * $Date: 1996/10/30 21:58:59 $
  5.  * $Revision: 1.2 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: memcmp,v $
  10.  * Revision 1.2  1996/10/30 21:58:59  unixlib
  11.  * Massive changes made by Nick Burret and Peter Burwood.
  12.  *
  13.  * Revision 1.1  1996/04/19 21:26:42  simon
  14.  * Initial revision
  15.  *
  16.  ***************************************************************************/
  17.  
  18. static const char rcs_id[] = "$Id: memcmp,v 1.2 1996/10/30 21:58:59 unixlib Rel $";
  19.  
  20. #include <string.h>
  21.  
  22. int
  23. memcmp (const void *s1, const void *s2, size_t n)
  24. {
  25.   register unsigned char *_s1 = (unsigned char *) s1, *_s2 = (unsigned char *) s2;
  26.  
  27.   while (n & 0x07)
  28.     {
  29.       if (*_s1 != *_s2)
  30.     goto differs;
  31.       _s1++, _s2++;
  32.       n--;
  33.     }
  34.   n >>= 3;
  35.   while (n)
  36.     {
  37.       if (*_s1 != *_s2)
  38.     goto differs;
  39.       _s1++, _s2++;
  40.       if (*_s1 != *_s2)
  41.     goto differs;
  42.       _s1++, _s2++;
  43.       if (*_s1 != *_s2)
  44.     goto differs;
  45.       _s1++, _s2++;
  46.       if (*_s1 != *_s2)
  47.     goto differs;
  48.       _s1++, _s2++;
  49.       if (*_s1 != *_s2)
  50.     goto differs;
  51.       _s1++, _s2++;
  52.       if (*_s1 != *_s2)
  53.     goto differs;
  54.       _s1++, _s2++;
  55.       if (*_s1 != *_s2)
  56.     goto differs;
  57.       _s1++, _s2++;
  58.       if (*_s1 != *_s2)
  59.     goto differs;
  60.       _s1++, _s2++;
  61.       n--;
  62.     }
  63.  
  64.   if (n == 0)
  65.     return 0;
  66.  
  67. differs:
  68.   return (*_s1 - *_s2);
  69. }
  70.  
  71. int bcmp (const void *s1, const void *s2, size_t n)
  72. {
  73.   return memcmp (s1, s2, n);
  74. }
  75.